<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Main extends CI_Controller {
	public function __construct(){
		parent::__construct();
		$this->output->nocache();
		$this -> form_validation -> set_error_delimiters('<p class="help-block danger">', '</p>');
	}
	public function index()
	{
		$data['title']="Home";
		$data['locations']=$this->model_globals->select_all('job_locations');
		$categories=$this->model_globals->select_all('job_categories')->result();
		$option = $this->get_job_category_options($categories);
		$data['categories']=$option;
		$data['browse_locations']=$this->model_jobs->brow_jobs_by_location();
		$data['browse_categories']=$this->model_jobs->browse_jobs_by_category();
		$data['browse_companies']=$this->model_jobs->brow_jobs_by_company();
		$data['latest_jobs']=$this->model_jobs->list_lastest_jobs(10)->result();
		$data['feature_employers']=$this->model_jobs->fearture_employer();
		$data['feature_jobs']=$this->model_jobs->fearture_job();
		$this->load->view(F_MASTER."index",$data);
	}
	public function get_job_category_options($categories){
		$option='';
		foreach ($categories as $category) {
			$category_id = $category -> job_category_id;
			$name = $category -> name;
			//$option .= '<optgroup label="' . $name . '">';
			$option .= '<option value="' . $category_id . '-0 " style="color:#3C8DBC;">' . $name . '</option>';
			$sub_categories = $this -> model_globals -> select_where('job_sub_categories', array('using_job_category_id' => $category_id)) -> result();
			foreach ($sub_categories as $sub_category) {
				$sub_category_id = $sub_category -> job_sub_category_id;
				$sub_name = $sub_category -> name;
				$option .= '<option value="' . $category_id . '-' . $sub_category_id . '">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' . $sub_name . '</option>';
			}
			//$option .= '</optgroup>';
		}
		return $option;
		
	}
}
